package cn.wolfcode.luowowo.article.controller;

import cn.wolfcode.luowowo.article.domain.Strategy;
import cn.wolfcode.luowowo.article.domain.StrategyCatalog;
import cn.wolfcode.luowowo.article.service.IStrategyCatalogService;
import cn.wolfcode.luowowo.article.service.IStrategyService;
import cn.wolfcode.luowowo.common.query.StrategyCatalogQueryObject;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/strategyCatalog")
public class StrategyCatalogController {
    @Reference
    private IStrategyCatalogService strategyCatalogService;
    @Reference
    private IStrategyService strategyService;
    @RequestMapping("/list")
    public String list(Model model,@ModelAttribute("qo") StrategyCatalogQueryObject qo){
        //查询列表
        PageInfo pageInfo = strategyCatalogService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        //查询出所有的攻略共享到页面 strategies
        List<Strategy> strategies = strategyService.selectAllStrategy();
        model.addAttribute("strategies",strategies);
        return "strategyCatalog/list";
    }


    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyCatalog strategyCatalog){
        //添加或者保存
        strategyCatalogService.saveOrUpdate(strategyCatalog);
        return new AjaxResult();
    }
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(Long id){
        //添加或者保存
        strategyCatalogService.deleteById(id);
        return new AjaxResult();
    }

}
